package test01_homework;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client {

    private Socket socket;

    public Client() {
        try {
            System.out.println("正在连接客户端……");
            socket = new Socket("localhost", 8088);
            System.out.println("与服务端建立连接！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void start() {
        try {
            OutputStream out = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(out,StandardCharsets.UTF_8);
            BufferedWriter bw = new BufferedWriter(osw);
            PrintWriter pw = new PrintWriter(bw,true);
            pw.println("你好");


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Client client = new Client();//实例化会调用构造器会初始化客户端
        client.start();//调用start开始客户端工作
        //实际开发中不会在main方法中写逻辑，因为静态方法之能引用静态资源，使用有局限性
    }


}
